﻿package mortal.game.view.task.view.render
{
    import Message.DB.Tables.*;
    import com.mui.controls.*;
    import com.mui.utils.*;
    import extend.language.*;
    import flash.events.*;
    import mortal.common.*;
    import mortal.component.gLinkText.*;
    import mortal.component.gconst.*;
    import mortal.game.cache.*;
    import mortal.game.resource.*;
    import mortal.game.resource.info.*;
    import mortal.game.view.common.*;
    import mortal.game.view.task.data.*;

    public class TaskTrackBase extends GSprite
    {
        protected var _bodySprite:GSprite;
        protected var _taskInfo:TaskInfo;
        protected var _dailyInfo:TDailyViewConfig;
        protected var _txts:Array;
        protected var _txtTitle:GTextFiled;

        public function TaskTrackBase()
        {
            return;
        }// end function

        public function setMyData(param1) : void
        {
            if (param1 is TaskInfo)
            {
                this.taskInfo = param1 as TaskInfo;
            }
            else
            {
                this.copyInfo = param1 as TDailyViewConfig;
            }
            return;
        }// end function

        public function get isGuiding() : Boolean
        {
            return false;
        }// end function

        public function set copyInfo(param1:TDailyViewConfig) : void
        {
            this._dailyInfo = param1;
            return;
        }// end function

        public function get copyInfo() : TDailyViewConfig
        {
            return this._dailyInfo;
        }// end function

        public function get taskInfo() : TaskInfo
        {
            return this._taskInfo;
        }// end function

        public function set taskInfo(param1:TaskInfo) : void
        {
            var _loc_3:GLinkTextData = null;
            var _loc_5:int = 0;
            this._taskInfo = param1;
            var _loc_2:* = this._taskInfo.stask.getNpc;
            _loc_3 = GLinkTextDataParser.parseDataFromNpcId(_loc_2, param1, 20161);
            var _loc_4:* = this.getText(0);
            _loc_4.isShowNum = false;
            _loc_4.y = 18;
            _loc_4.setLinkText(_loc_3, this.getExtendHtmlText());
            if (TaskUtil.isLoopTask(this._taskInfo))
            {
                _loc_5 = Cache.instance.task.getGroupFinishCount(this._taskInfo.stask.group);
                this._txtTitle.htmlText = Language.getStringByParam(21185, _loc_5, GameConst.TConstLoopTaskNum);
            }
            else
            {
                this._txtTitle.htmlText = this.getTitleName();
            }
            return;
        }// end function

        public function updateGuide() : void
        {
            return;
        }// end function

        public function removeGuide() : void
        {
            return;
        }// end function

        protected function getExtendHtmlText() : String
        {
            return "";
        }// end function

        protected function getTaskStatusText() : String
        {
            return this._taskInfo.getStatusName(true);
        }// end function

        protected function getTitleName() : String
        {
            var _loc_1:ColorInfo = null;
            if (this._taskInfo.playerTask != null && this._taskInfo.playerTask.extend > 0)
            {
                _loc_1 = ColorConfig.instance.getItemColor(this._taskInfo.playerTask.extend);
                if (_loc_1 != null)
                {
                    return "<font color=\'" + _loc_1.color + "\'>" + this._taskInfo.stask.name + "</font>" + this.getTaskStatusText();
                }
                return this._taskInfo.stask.name + this.getTaskStatusText();
            }
            return this._taskInfo.stask.name + this.getTaskStatusText();
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._bodySprite = UICompomentPool.getUICompoment(GSprite);
            this.addChild(this._bodySprite);
            this._txtTitle = UIFactory.gTextField("", 0, 0, 200, 20, this);
            this._txtTitle.textColor = 16777215;
            this._txts = [];
            this._txtTitle.addEventListener(TextEvent.LINK, this.linkHandler);
            return;
        }// end function

        protected function linkHandler(event:TextEvent) : void
        {
            var _loc_2:* = event.text;
            this.linkImpl(_loc_2);
            return;
        }// end function

        public function linkImpl(param1:String) : void
        {
            return;
        }// end function

        protected function getText(param1:int) : GLinkText
        {
            var _loc_2:GLinkText = null;
            if (this._txts[param1] == null)
            {
                _loc_2 = UICompomentPool.getUICompoment(GLinkText) as GLinkText;
                _loc_2.widthConst = 182;
                _loc_2.x = 11;
                this._bodySprite.addChild(_loc_2);
                this._txts[param1] = _loc_2;
            }
            return this._txts[param1];
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            this._txtTitle.removeEventListener(TextEvent.LINK, this.linkHandler);
            this._txtTitle.dispose(param1);
            this._txtTitle = null;
            this._bodySprite.dispose(param1);
            this._bodySprite = null;
            this._taskInfo = null;
            DisplayUtil.delNotUse(this._txts, 0);
            this._txts = null;
            return;
        }// end function

        override public function get height() : Number
        {
            if (this._txts == null || this._txts.length == 0)
            {
                return 20;
            }
            var _loc_1:* = this._txts[(this._txts.length - 1)];
            return _loc_1.y + _loc_1.height;
        }// end function

        override public function get width() : Number
        {
            var _loc_3:GLinkText = null;
            var _loc_4:int = 0;
            if (this._txts == null || this._txts.length == 0)
            {
                if (this._txtTitle != null && this._txtTitle.parent != null)
                {
                    return this._txtTitle.textWidth;
                }
                return 180;
            }
            var _loc_1:int = 0;
            var _loc_2:int = 0;
            while (_loc_2 < this._txts.length)
            {
                
                _loc_3 = this._txts[_loc_2];
                _loc_4 = _loc_3.width;
                if (_loc_4 > _loc_1)
                {
                    _loc_1 = _loc_4;
                }
                _loc_2++;
            }
            return _loc_1;
        }// end function

    }
}
